import { request } from '@/utils/request'
import type {
  KnowledgeParams,
  KnowledgePage,
  DoctorPage,
  queryParam,
  followType,
  TopDep,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  OrderQuery,
  ConsultOrderPage
} from '@/types/consult'
// 获取知识列表
export const getKnowledgePage = (param: KnowledgeParams) =>
  request<KnowledgePage>('GET', 'patient/home/knowledge', param)
// 获取医生列表
export const getDoctorList = (param: queryParam) =>
  request<DoctorPage>('GET', 'home/page/doc', param)
// 关注和取消关注
export const followOrUnfollow = (param: { type: followType; id: string }) =>
  request('POST', 'like', param)
// 获取所有的科室
export const getAllDep = () => request<TopDep[]>('GET', 'dep/all')

//上传图像
export const uploadImg = (data: FormData) =>
  request<{ id: string; url: string }>('POST', 'upload', data)

// 生成计算就诊信息和抵扣信息
export const createConsultRrderPre = (data: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('get', 'patient/consult/order/pre', data)

// 生成订单id
export const createOrder = (data: PartialConsult) =>
  request<{ id: string }>('POST', 'patient/consult/order', data)

// 支付
export const consultPay = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('POST', 'patient/consult/pay', data)

// 获取订单详情
export const getOrderDeatil = (orderId: string) =>
  request<ConsultOrderItem>('GET', 'patient/consult/order/detail', { orderId })

// 获取未读消息
export const getUnReadList = () =>
  request<number>('get', 'patient/message/unRead/all')

// 获取处方信息
export const getPrescriptionInfo = (id: string) =>
  request<{ url: string }>('GET', `patient/consult/prescription/${id}`)
// 提交评价
export const submitEvaluate = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 1 | 0
}) => request('post', 'patient/order/evaluate', data)

// 获取问诊记录
export const getConsultList = (data: OrderQuery) =>
  request<ConsultOrderPage>('GET', 'patient/consult/order/list', data)
// 取消订单/问诊
export const orderCancel = (id: string) =>
  request('PUT', `patient/order/cancel/${id}`)
// 删除订单
export const deleteOrder = (id: string) =>
  request('DELETE', `patient/order/${id}`)
